import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { MockService } from './mock.service';
import { CreateMockDto } from './dto/create-mock.dto';
import { UpdateMockDto } from './dto/update-mock.dto';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import {
  BaseResponseMockDto,
  QueryMockResponseDto,
  ResponseDto,
} from './dto/response-mock.dto';
import { QueryMockListDto } from './dto/request-mock.dto';
import { DeleteResult, UpdateResult } from 'typeorm';

@Controller('mock')
export class MockController {
  constructor(private readonly mockService: MockService) {}

  @Post()
  @ApiOperation({ summary: '创建mock' })
  @ApiResponse({
    status: 200,
    description: '成功数据',
    type: ResponseDto(BaseResponseMockDto),
  })
  create(@Body() createMockDto: CreateMockDto) {
    return this.mockService.create(createMockDto);
  }

  @Get()
  @ApiOperation({ summary: '列表数据' })
  @ApiResponse({
    status: 200,
    description: '成功数据',
    type: ResponseDto(QueryMockResponseDto),
  })
  findAll(@Query() query: QueryMockListDto) {
    return this.mockService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '查找' })
  @ApiResponse({
    status: 200,
    description: '成功数据',
    type: ResponseDto(BaseResponseMockDto),
  })
  findOne(@Param('id') id: string) {
    return this.mockService.findOne(+id);
  }

  @Post(':pathName')
  @ApiOperation({ summary: '按pathName查找' })
  @ApiResponse({
    status: 200,
    description: '成功数据',
    type: ResponseDto(Object),
  })
  findPathNameItem(@Param('pathName') pathName: string) {
    return this.mockService.findPathName(pathName);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新' })
  @ApiResponse({
    status: 200,
    description: '成功数据',
    type: ResponseDto(UpdateResult),
  })
  update(@Param('id') id: string, @Body() updateMockDto: UpdateMockDto) {
    return this.mockService.update(+id, updateMockDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除' })
  @ApiResponse({
    status: 200,
    description: '成功数据',
    type: ResponseDto(DeleteResult),
  })
  remove(@Param('id') id: string) {
    return this.mockService.remove(+id);
  }
}
